#pragma once
#include "targetver.h"
#include "dxroids.h"

#include <dsound.h>
#include <map>
#include <vector>

namespace dxroids
{
   class SoundManager
   {

   public:      

      SoundManager();

      void Play(SoundEffect _effect, bool _loop = false) const;
      void Stop(SoundEffect _effect) const;

      HRESULT Initialize(HWND _window_handle);

      bool Mute();
      void UnMute();

   private:

      bool LoadWaveFile(BYTE * _buffer, DWORD _buffer_length, DXROIDS_COM_PTR<IDirectSoundBuffer>& secondaryBuffer);
      bool LoadWaveFromResource(LPTSTR _resource_id, DXROIDS_COM_PTR<IDirectSoundBuffer>& _sound_buffer);
      void LoadWaveFromResource(LPTSTR _resource_id, SoundEffect _effect);
      DXROIDS_COM_PTR<IDirectSoundBuffer> FindSoundEffect(SoundEffect _effect) const;

   private:

      DXROIDS_COM_PTR<IDirectSound> sound_device_;
      
      // this is completely custome to our application 
      typedef DXROIDS_COM_PTR<IDirectSoundBuffer> sound_buffer_type;
      typedef std::vector<sound_buffer_type> sound_buffer_list_type;
      typedef std::map<SoundEffect, sound_buffer_type> sound_buffer_map_type;

      sound_buffer_list_type sound_effect_fire_;
      sound_buffer_list_type sound_effect_band_small_;
      sound_buffer_list_type sound_effect_band_medium_;
      sound_buffer_list_type sound_effect_band_large_;      
      sound_buffer_map_type sound_effects_;

      bool muted_;
      bool initialized_;
   };
}

 inline bool dxroids::SoundManager::Mute()
 {
    bool const b = muted_;
    muted_ = true;
    return b;
 }

 inline void dxroids::SoundManager::UnMute()
 {
    muted_ = false;
 }